package com.grad.why.studentsystem.controller;

import com.grad.why.studentsystem.domain.*;
import com.grad.why.studentsystem.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/util")
public class UtilController {
    @Autowired
    private NationService nationService;

    @Autowired
    private ClassinfoService classinfoService;

    @Autowired
    private TeacherService teacherService;

    @Autowired
    private ProjectService projectService;

    @Autowired
    private GradeService gradeService;

    @Autowired
    private CourseService courseService;

    @Autowired
    private ClassRoomService classRoomService;

    @Autowired
    private MenuService menuService;

    @Autowired
    private static OptionparamsService optionparamsService;

    @Autowired
    private static FaceInfoService faceInfoService;

    @RequestMapping("/getNations")
    @ResponseBody
    public List<Nation> getNations(){
        try{
            return nationService.getNations();
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    @RequestMapping("/getClassInfos")
    @ResponseBody
    public List<Classinfo> getClassInfos(){
        try{
            return classinfoService.getClassInfos();
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    @RequestMapping("/getTeacherPosition")
    @ResponseBody
    public List<Teacherposition> getTeacherPosition(){
        try{
            return teacherService.getTeacherPosition();
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    @RequestMapping("/getWorkRoles")
    @ResponseBody
    public List<Workrole> getWorkRoles(){
        try{
            return teacherService.getWorkRoles();
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    @RequestMapping("/getProjects")
    @ResponseBody
    public List<Project> getProjects(){
        try{
            return projectService.getProjects();
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    @RequestMapping("/getGrades")
    @ResponseBody
    public List<Grade> getGrades(){
        try{
            return gradeService.getGrades();
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }


    @RequestMapping("/getCourseTypes")
    @ResponseBody
    public List<Coursetype> getCourseTypes(){
        try{
            List<Coursetype> coursetypes = courseService.getCourseTypes();
            return coursetypes;
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    @RequestMapping("/getCourseInfos")
    @ResponseBody
    public List<Course> getCourseInofs(){
        try{
            return courseService.getCourseInfos();
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    @RequestMapping("/getTeacherInfos")
    @ResponseBody
    public List<Teacher> getTeacherInfos(){
        try{
            return teacherService.getTeacherInfos();
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    @RequestMapping("/getCourseInfosByCid/{cid}")
    @ResponseBody
    public Course getCourseInfosByCid(@PathVariable("cid") String cid){
        try{
            return courseService.getCourseInfoByCid(Integer.parseInt(cid));
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    @RequestMapping("/ClassRoominfos")
    @ResponseBody
    public List<ClassRoom> classRoom(){
        try{
            return classRoomService.getClassRoomInfos();
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    @RequestMapping("/getCourseInfosByRunning")
    @ResponseBody
    public List<Course> getCourseInfosByRunning(){
        try{
            return courseService.getCourseInfosByRunning();
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    @RequestMapping("/getMenuInfos")
    @ResponseBody
    public List<Menu> getMenuInfos(){
        try{
            return menuService.getMenuInfos();
        }catch (Exception E){
            E.printStackTrace();
        }
        return null;
    }

//    @RequestMapping("/init")
//    @ResponseBody
//    public String[] init(){
//        String[] datas = new String[2];
//        datas[0] = "[8500, 9000, 8500, 9000, 8500, 9000, 8500, 9000, 8500, 9000, 9000, 8500]";
//        datas[1] = "[10000, 12000, 10000, 12000,10000, 12000,10000, 12000,10000, 12000,10000, 12000]";
//        datas[0] = "[";
//        datas[1] = "[";
//
//        ArrryList<Salary> salaryArrryList = new ArrayList<Salary>();
//        for(int i = 0;i<salaryArrryList.size();i++){
//            if(i == salaryArrryList.size() - 1){
//                datas[0] += salaryArrryList.get(i).getSalary()+"]";
//                datas[1] += salaryArrryList.get(i).getSalary()+"]";
//            }else{
//                datas[0] += salaryArrryList.get(i).getSalary()+",";
//                datas[1] += salaryArrryList.get(i).getSalary()+",";
//            }
//        }
//
//        return datas;
//    }


}
